/*
 * Copyright (C) 2015 Zhang Rui <bbcallen@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * https://github.com/Bilibili/jni4android
 * This file is automatically generated by jni4android, do not modify.
 */

#include "Extractor.h"

typedef struct J4AC_ohos_media_extractor_Extractor {
    jclass id;

    jmethodID constructor_Extractor;
    jmethodID method_setSource;
    jmethodID method_getTotalStreams;
    jmethodID method_getStreamFormat;
    jmethodID method_specifyStream;
    jmethodID method_getIntValue;
    jmethodID method_readBuffer;
    jmethodID method_getFrameTimestamp;
    jmethodID method_next;
    jmethodID method_release;
} J4AC_ohos_media_extractor_Extractor;
static J4AC_ohos_media_extractor_Extractor class_J4AC_ohos_media_extractor_Extractor;

jobject J4AC_ohos_media_extractor_Extractor__Extractor(JNIEnv *env)
{
    return (*env)->NewObject(env, class_J4AC_ohos_media_extractor_Extractor.id, class_J4AC_ohos_media_extractor_Extractor.constructor_Extractor);
}

jobject J4AC_ohos_media_extractor_Extractor__Extractor__catchAll(JNIEnv *env)
{
    jobject ret_object = J4AC_ohos_media_extractor_Extractor__Extractor(env);
    if (J4A_ExceptionCheck__catchAll(env) || !ret_object) {
        return NULL;
    }

    return ret_object;
}

jobject J4AC_ohos_media_extractor_Extractor__Extractor__asGlobalRef__catchAll(JNIEnv *env)
{
    jobject ret_object   = NULL;
    jobject local_object = J4AC_ohos_media_extractor_Extractor__Extractor__catchAll(env);
    if (J4A_ExceptionCheck__catchAll(env) || !local_object) {
        ret_object = NULL;
        goto fail;
    }

    ret_object = J4A_NewGlobalRef__catchAll(env, local_object);
    if (!ret_object) {
        ret_object = NULL;
        goto fail;
    }

fail:
    J4A_DeleteLocalRef__p(env, &local_object);
    return ret_object;
}

jboolean J4AC_ohos_media_extractor_Extractor__setSource(JNIEnv *env, jobject thiz, jobject source)
{
    return (*env)->CallBooleanMethod(env, thiz, class_J4AC_ohos_media_extractor_Extractor.method_setSource, source);
}

jboolean J4AC_ohos_media_extractor_Extractor__setSource__catchAll(JNIEnv *env, jobject thiz, jobject source)
{
    jboolean ret_value = J4AC_ohos_media_extractor_Extractor__setSource(env, thiz, source);
    if (J4A_ExceptionCheck__catchAll(env)) {
        return false;
    }

    return ret_value;
}

jint J4AC_ohos_media_extractor_Extractor__getTotalStreams(JNIEnv *env, jobject thiz)
{
    return (*env)->CallIntMethod(env, thiz, class_J4AC_ohos_media_extractor_Extractor.method_getTotalStreams);
}

jint J4AC_ohos_media_extractor_Extractor__getTotalStreams__catchAll(JNIEnv *env, jobject thiz)
{
    jint ret_value = J4AC_ohos_media_extractor_Extractor__getTotalStreams(env, thiz);
    if (J4A_ExceptionCheck__catchAll(env)) {
        return 0;
    }

    return ret_value;
}

jobject J4AC_ohos_media_extractor_Extractor__getStreamFormat(JNIEnv *env, jobject thiz, jint id)
{
    return (*env)->CallObjectMethod(env, thiz, class_J4AC_ohos_media_extractor_Extractor.method_getStreamFormat, id);
}

jobject J4AC_ohos_media_extractor_Extractor__getStreamFormat__catchAll(JNIEnv *env, jobject thiz, jint id)
{
    jobject ret_object = J4AC_ohos_media_extractor_Extractor__getStreamFormat(env, thiz, id);
    if (J4A_ExceptionCheck__catchAll(env) || !ret_object) {
        return NULL;
    }

    return ret_object;
}

jobject J4AC_ohos_media_extractor_Extractor__getStreamFormat__asGlobalRef__catchAll(JNIEnv *env, jobject thiz, jint id)
{
    jobject ret_object   = NULL;
    jobject local_object = J4AC_ohos_media_extractor_Extractor__getStreamFormat__catchAll(env, thiz, id);
    if (J4A_ExceptionCheck__catchAll(env) || !local_object) {
        ret_object = NULL;
        goto fail;
    }

    ret_object = J4A_NewGlobalRef__catchAll(env, local_object);
    if (!ret_object) {
        ret_object = NULL;
        goto fail;
    }

fail:
    J4A_DeleteLocalRef__p(env, &local_object);
    return ret_object;
}

jboolean J4AC_ohos_media_extractor_Extractor__specifyStream(JNIEnv *env, jobject thiz, jint id)
{
    return (*env)->CallBooleanMethod(env, thiz, class_J4AC_ohos_media_extractor_Extractor.method_specifyStream, id);
}

jboolean J4AC_ohos_media_extractor_Extractor__specifyStream__catchAll(JNIEnv *env, jobject thiz, jint id)
{
    jboolean ret_value = J4AC_ohos_media_extractor_Extractor__specifyStream(env, thiz, id);
    if (J4A_ExceptionCheck__catchAll(env)) {
        return false;
    }

    return ret_value;
}

jint J4AC_ohos_media_extractor_Extractor__getIntValue(JNIEnv *env, jobject thiz, jstring key)
{
    return (*env)->CallIntMethod(env, thiz, class_J4AC_ohos_media_extractor_Extractor.method_getIntValue, key);
}

jint J4AC_ohos_media_extractor_Extractor__getIntValue__catchAll(JNIEnv *env, jobject thiz, jstring key)
{
    jint ret_value = J4AC_ohos_media_extractor_Extractor__getIntValue(env, thiz, key);
    if (J4A_ExceptionCheck__catchAll(env)) {
        return 0;
    }

    return ret_value;
}

jint J4AC_ohos_media_extractor_Extractor__getIntValue__withCString(JNIEnv *env, jobject thiz, const char *key_cstr__)
{
    jint ret_value = 0;
    jstring key = NULL;

    key = (*env)->NewStringUTF(env, key_cstr__);
    if (J4A_ExceptionCheck__throwAny(env) || !key)
        goto fail;

    ret_value = J4AC_ohos_media_extractor_Extractor__getIntValue(env, thiz, key);
    if (J4A_ExceptionCheck__throwAny(env)) {
        ret_value = 0;
        goto fail;
    }

fail:
    J4A_DeleteLocalRef__p(env, &key);
    return ret_value;
}

jint J4AC_ohos_media_extractor_Extractor__getIntValue__withCString__catchAll(JNIEnv *env, jobject thiz, const char *key_cstr__)
{
    jint ret_value = 0;
    jstring key = NULL;

    key = (*env)->NewStringUTF(env, key_cstr__);
    if (J4A_ExceptionCheck__catchAll(env) || !key)
        goto fail;

    ret_value = J4AC_ohos_media_extractor_Extractor__getIntValue__catchAll(env, thiz, key);
    if (J4A_ExceptionCheck__catchAll(env)) {
        ret_value = 0;
        goto fail;
    }

fail:
    J4A_DeleteLocalRef__p(env, &key);
    return ret_value;
}

jint J4AC_ohos_media_extractor_Extractor__readBuffer(JNIEnv *env, jobject thiz, jobject buf, jint offset)
{
    return (*env)->CallIntMethod(env, thiz, class_J4AC_ohos_media_extractor_Extractor.method_readBuffer, buf, offset);
}

jint J4AC_ohos_media_extractor_Extractor__readBuffer__catchAll(JNIEnv *env, jobject thiz, jobject buf, jint offset)
{
    jint ret_value = J4AC_ohos_media_extractor_Extractor__readBuffer(env, thiz, buf, offset);
    if (J4A_ExceptionCheck__catchAll(env)) {
        return 0;
    }

    return ret_value;
}

jlong J4AC_ohos_media_extractor_Extractor__getFrameTimestamp(JNIEnv *env, jobject thiz)
{
    return (*env)->CallLongMethod(env, thiz, class_J4AC_ohos_media_extractor_Extractor.method_getFrameTimestamp);
}

jlong J4AC_ohos_media_extractor_Extractor__getFrameTimestamp__catchAll(JNIEnv *env, jobject thiz)
{
    jlong ret_value = J4AC_ohos_media_extractor_Extractor__getFrameTimestamp(env, thiz);
    if (J4A_ExceptionCheck__catchAll(env)) {
        return 0;
    }

    return ret_value;
}

jboolean J4AC_ohos_media_extractor_Extractor__next(JNIEnv *env, jobject thiz)
{
    return (*env)->CallBooleanMethod(env, thiz, class_J4AC_ohos_media_extractor_Extractor.method_next);
}

jboolean J4AC_ohos_media_extractor_Extractor__next__catchAll(JNIEnv *env, jobject thiz)
{
    jboolean ret_value = J4AC_ohos_media_extractor_Extractor__next(env, thiz);
    if (J4A_ExceptionCheck__catchAll(env)) {
        return false;
    }

    return ret_value;
}

jboolean J4AC_ohos_media_extractor_Extractor__release(JNIEnv *env, jobject thiz)
{
    return (*env)->CallBooleanMethod(env, thiz, class_J4AC_ohos_media_extractor_Extractor.method_release);
}

jboolean J4AC_ohos_media_extractor_Extractor__release__catchAll(JNIEnv *env, jobject thiz)
{
    jboolean ret_value = J4AC_ohos_media_extractor_Extractor__release(env, thiz);
    if (J4A_ExceptionCheck__catchAll(env)) {
        return false;
    }

    return ret_value;
}

int J4A_loadClass__J4AC_ohos_media_extractor_Extractor(JNIEnv *env)
{
    int         ret                   = -1;
    const char *J4A_UNUSED(name)      = NULL;
    const char *J4A_UNUSED(sign)      = NULL;
    jclass      J4A_UNUSED(class_id)  = NULL;
    int         J4A_UNUSED(api_level) = 0;

    if (class_J4AC_ohos_media_extractor_Extractor.id != NULL)
        return 0;

    sign = "ohos/media/extractor/Extractor";
    class_J4AC_ohos_media_extractor_Extractor.id = J4A_FindClass__asGlobalRef__catchAll(env, sign);
    if (class_J4AC_ohos_media_extractor_Extractor.id == NULL)
        goto fail;

    class_id = class_J4AC_ohos_media_extractor_Extractor.id;
    name     = "<init>";
    sign     = "()V";
    class_J4AC_ohos_media_extractor_Extractor.constructor_Extractor = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_extractor_Extractor.constructor_Extractor == NULL)
        goto fail;

    class_id = class_J4AC_ohos_media_extractor_Extractor.id;
    name     = "setSource";
    sign     = "(Lohos/media/common/Source;)Z";
    class_J4AC_ohos_media_extractor_Extractor.method_setSource = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_extractor_Extractor.method_setSource == NULL)
        goto fail;

    class_id = class_J4AC_ohos_media_extractor_Extractor.id;
    name     = "getTotalStreams";
    sign     = "()I";
    class_J4AC_ohos_media_extractor_Extractor.method_getTotalStreams = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_extractor_Extractor.method_getTotalStreams == NULL)
        goto fail;

    class_id = class_J4AC_ohos_media_extractor_Extractor.id;
    name     = "getStreamFormat";
    sign     = "(I)Lohos/media/common/Format;";
    class_J4AC_ohos_media_extractor_Extractor.method_getStreamFormat = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_extractor_Extractor.method_getStreamFormat == NULL)
        goto fail;

    class_id = class_J4AC_ohos_media_extractor_Extractor.id;
    name     = "specifyStream";
    sign     = "(I)Z";
    class_J4AC_ohos_media_extractor_Extractor.method_specifyStream = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_extractor_Extractor.method_specifyStream == NULL)
        goto fail;

    class_id = class_J4AC_ohos_media_extractor_Extractor.id;
    name     = "getIntValue";
    sign     = "(Ljava/lang/String;)I";
    class_J4AC_ohos_media_extractor_Extractor.method_getIntValue = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_extractor_Extractor.method_getIntValue == NULL)
        goto fail;

    class_id = class_J4AC_ohos_media_extractor_Extractor.id;
    name     = "readBuffer";
    sign     = "(Ljava/nio/ByteBuffer;I)I";
    class_J4AC_ohos_media_extractor_Extractor.method_readBuffer = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_extractor_Extractor.method_readBuffer == NULL)
        goto fail;

    class_id = class_J4AC_ohos_media_extractor_Extractor.id;
    name     = "getFrameTimestamp";
    sign     = "()J";
    class_J4AC_ohos_media_extractor_Extractor.method_getFrameTimestamp = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_extractor_Extractor.method_getFrameTimestamp == NULL)
        goto fail;

    class_id = class_J4AC_ohos_media_extractor_Extractor.id;
    name     = "next";
    sign     = "()Z";
    class_J4AC_ohos_media_extractor_Extractor.method_next = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_extractor_Extractor.method_next == NULL)
        goto fail;

    class_id = class_J4AC_ohos_media_extractor_Extractor.id;
    name     = "release";
    sign     = "()Z";
    class_J4AC_ohos_media_extractor_Extractor.method_release = J4A_GetMethodID__catchAll(env, class_id, name, sign);
    if (class_J4AC_ohos_media_extractor_Extractor.method_release == NULL)
        goto fail;

    J4A_ALOGD("J4ALoader: OK: '%s' loaded\n", "ohos.media.extractor.Extractor");
    ret = 0;
fail:
    return ret;
}
